<?php
require_once('../controller/auth.php');
//Start session
	session_start();
	
	//Include database connection details
	require_once('../controller/inc/config.inc');
	
	//Array to store validation errors
	$errmsg_arr = array();
	
	//Validation error flag
	$errflag = false;
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db("ttc_teachers");
	if(!$db) {
		die("Unable to select database");
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
<title>TMIS-Training Module</title>

<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
<!-- Le styles -->
<link rel="stylesheet" href="../assets/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/bootstrap-responsive.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/font-awesome.css" type="text/css" />
<script type="text/javascript" src="../assets/js/jquery.min.js"></script>

<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap-popover.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap-tooltip.js"></script>
<script>
$(function ()
{ 
$("input").popover({trigger: 'focus', 'placement':'right'});

$("textarea").popover({trigger: 'focus'});


$('#tab').tooltip({'placement':'right', 'trigger' : 'hover'});

$('a').tooltip({'placement':'bottom', 'trigger' : 'hover'});	
});
</script>
<script type="text/javascript">
$(document).ready(function()
{
$("#prov_select").change(function()
{
$('#gen_rep').hide();
var pro_name=$(this).val();
var dataString = 'pro_id='+ pro_name;

$.ajax
({
type: "POST",
url: "execute/list_ttc.php",
data: dataString,
cache: false,
success: function(html)
{
$(".ttc").html(html);
} 
});

});

});
</script>
<style>
body {
    padding-top: 60px;
    padding-bottom: 40px;
}

.sidebar-nav {
    padding: 9px 0;
}

.dropdown-menu .sub-menu {
    left: 100%;
    position: absolute;
    top: 0;
    visibility: hidden;
    margin-top: -1px;
}

.dropdown-menu li:hover .sub-menu {
    visibility: visible;
    display: block;
}

.navbar .sub-menu:before {
    border-bottom: 7px solid transparent;
    border-left: none;
    border-right: 7px solid rgba(0, 0, 0, 0.2);
    border-top: 7px solid transparent;
    left: -7px;
    top: 10px;
}
.navbar .sub-menu:after {
    border-top: 6px solid transparent;
    border-left: none;
    border-right: 6px solid #fff;
    border-bottom: 6px solid transparent;
    left: 10px;
    top: 11px;
    left: -6px;
}
</style>
<!-- Le fav and touch icons -->

</head>

<body>
<div class="container-fluid">
<!--TOp Nav-->
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
      <div class="container-fluid">
        <a data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </a>
        <a href="#" class="brand">TMIS | SMIS</a>
        <div class="nav-collapse">
          <ul class="nav">
            <li><a href="../dashboard.php">Home</a></li>
            
            <li class="dropdown active">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">Colleges <b class="caret"></b></a>
              <ul class="dropdown-menu">
               
                <li><a href="#">TTC Information</a></li>
                <li><a href="ttc_teachers_info.php">TTC Teachers</a></li>
                <li><a href="#">Provinces</a></li>
              
              </ul>
            </li>
            
            
            <!--Students-->
            <li class="dropdown">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">Students <b class="caret"></b></a>
              <ul class="dropdown-menu">
              
                <li><a href="#">Students Information</a></li>
                <li><a href="#">Add Students</a></li>
                <li><a href="#">Modify Students</a></li>
                <li class="divider"></li>
                <li class="nav-header">Assign</li>
                <li><a href="#">Class</a></li>
                <li><a href="#">Department</a></li>
                <li class="divider"></li>
                
                <li><a href="#">Transfer In</a></li>
                <li><a href="#">Transfer Out</a></li>
                <li class="divider"></li>
                <li><a href="#">Reports</a></li>
                <li class="divider"></li>
                <li><a href="#">Setup</a></li>
                
              </ul>
            </li>
            <!--/Students-->
            
            <!--Grades-->
            <li class="dropdown">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">Grades <b class="caret"></b></a>
              <ul class="dropdown-menu">
              
                <li><a href="#">Transcripts</a></li>
                <li><a href="#">Reports</a></li>
                <li><a href="#">Setup</a></li>
                <li class="divider"></li>
               
                <li><a href="#">Utilities</a></li>
                
                
                
              </ul>
            </li>
            <!--/Grades-->
            
              <!--Attendance-->
            <li class="dropdown">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">Attendance <b class="caret"></b></a>
              <ul class="dropdown-menu">
              
                <li><a href="#">Administration</a></li>
                <li><a href="#">Reports</a></li>
                <li><a href="#">Setup</a></li>
                <li class="divider"></li>
               
                <li><a href="#">Utilities</a></li>
                
                
                
              </ul>
            </li>
            <!--/Attendance-->
            
            <!--User-->
            <li class="dropdown">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">User <b class="caret"></b></a>
              <ul class="dropdown-menu">
              
                <li><a href="#">User Info</a></li>
                <li><a href="#">Add a User</a></li>
                <li><a href="#">Preferences</a></li>
                <li class="divider"></li>
               
                <li><a href="#">Setup</a></li>
                
                
                
              </ul>
            </li>
            <!--/User-->
               <!--Tools-->
            <li class="dropdown">
              <a data-toggle="dropdown" class="dropdown-toggle" href="#">Tools <b class="caret"></b></a>
              <ul class="dropdown-menu">
              
                <li><a href="#">Access Log</a></li>
                <li><a href="#">Delete Log</a></li>
                <li><a href="#">Rollover</a></li>
                <li class="divider"></li>
               
                <li><a href="#">Backup Database</a></li>
                
                
                
              </ul>
            </li>
            <!--/User-->
            
            
            
          </ul>
          <form action="" class="navbar-search pull-left">
            <input type="text" placeholder="Search" class="search-query span2">
          </form>
          <ul class="nav pull-right">
            
            
            <div class="pull-right">
                <ul class="nav pull-right">
                    <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Welcome, <?php echo $_SESSION['SESS_FIRST_NAME'] . " " . $_SESSION['SESS_LAST_NAME'];?> <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="/user/preferences"><i class="icon-cog"></i> Preferences</a></li>
                            <li><a href="/help/support"><i class="icon-envelope"></i> Contact Support</a></li>
                            <li class="divider"></li>
                            <li><a href="controller/logout.php"><i class="icon-off"></i> Logout</a></li>
                        </ul>
                    </li>
                </ul>
              </div>
              
              
          </ul>
        </div><!-- /.nav-collapse -->
      </div>
  </div>
</div>








<script>
$(document).ready(function()
{
  //Handles menu drop down
  $('.dropdown-menu').find('form').click(function (e) {
        e.stopPropagation();
        });
  });
</script>


<!--/Top Nav-->
  <div class="row-fluid">
    
    <div class="span9">
	<!--Content-->


<h2>TTC Information</h2>
		<div id="tab" class="btn-group" data-toggle="buttons-radio">
		  <a href="#gen" class="btn active" data-toggle="tab">General Report</a>
		  <a href="#typevise" class="btn" data-toggle="tab">Type vise</a>
		  <a href="#addnew" class="btn" data-toggle="tab">Add New TTC</a>
		  
		</div>
 
		<div class="tab-content">
		  <div class="tab-pane active" id="gen">
		  <br/><br/>
		  <?php
		  echo "<div class='well' id='gen_rep'>";
			echo "<h4 class='text-error'>Total Number of TTCs, Type vise, Country vise</h4>"; 
			$qt=mysql_query("SELECT TTC_TYPE,COUNT(*) FROM ttc_information group by TTC_TYPE");
			$num=0;
			$arr_tot=Array('No of Main TTCs','No of Satelite TTCs','No of Sub  TTCs');
			echo "<table class='table table-bordered' style='width:50%'>";
			while($qt_row=mysql_fetch_array($qt)){
			echo "<th>" . $arr_tot[$num] . "</th><td>" . $qt_row[1] . "</td>";
			echo "</tr>";
			$num++;
			}	
			echo "</table>";
			echo "</div>";
		  ?>
		  Select Province:
		  <select id="prov_select">
		  	<option value="">Please Select a Provice</option>
		  	<?php
		  	mysql_query ('SET NAMES utf8');
		  	mysql_query('SET CHARACTER_SET utf8'); 
		  	$q=mysql_query("SELECT * FROM province order by PROV_NAME");
		  	while($row=mysql_fetch_array($q)){
			  	echo "<option value='$row[PROV_ID]'>" . $row['PROV_NAME'] . "</option>";
			  	
			  	}
		  	
		  	?>
		  </select>
		  
		  	<div class="ttc"></div> 
		  </div>
		  
		  <div class="tab-pane" id="typevise">
		  <br/>
		  <script type="text/javascript">
			$(document).ready(function()
			{
			$("#ttc_type").change(function()
			{
			var pro=$('#ttc_pro').attr('value');
			var tp=$(this).val();
			var dataString = 'pro='+ pro + '&tp='+ tp;
			
			$.ajax
			({
			type: "POST",
			url: "execute/list_type_ttc.php",
			data: dataString,
			cache: false,
			success: function(html)
			{
			$(".result_type").html(html);
			} 
			});
			
			});
			
			});
			</script>
		  Select Province:
		  <select id="ttc_pro">
		  	<option value="">Please Select a Provice</option>
		  	<?php
		  	mysql_query ('SET NAMES utf8');
		  	mysql_query('SET CHARACTER_SET utf8'); 
		  	$q_t=mysql_query("SELECT * FROM province order by PROV_NAME");
		  	while($row=mysql_fetch_array($q_t)){
			  	echo "<option value='$row[PROV_ID]'>" . $row['PROV_NAME'] . "</option>";
			  	
			  	}
		  	
		  	?>
		  </select>
		  
		   Select TTC Type:
		  <select id="ttc_type">
		  	<option value="">Please Select TTC Type</option>
		  	<option value="اساسی">اساسی</option>
		  	<option value="الحاقیه">الحاقیه</option>
		  	<option value="مرکزحمایوی">مرکزحمایوی</option>
		  </select>
		  
		  <div class="result_type"></div>
		  
		  </div>
		  
		  
		  <div class="tab-pane" id="addnew">
		  <br/>
		  <div id='add_result'></div>
		  
		  <script type="text/javascript">
			$(document).ready(function()
			{
			$("#sub_btn").click(function()
			{
			var ttc_name=$('#ttc_name').attr('value');
			var ttc_province=$('#ttc_province').attr('value');
			var ttc_type=$('#ttc_type').attr('value');
			var ttc_status=$('#ttc_status').attr('value');
			var ttc_location=$('#ttc_location').attr('value');
			var dataString = 'name='+ ttc_name + '&pro='+ ttc_province + '&type='+ ttc_type + '&stat='+ ttc_status + '&loc='+ ttc_location;
			
			$.ajax
			({
			type: "POST",
			url: "execute/add_ttc.php",
			data: dataString,
			cache: false,
			success: function(html)
			{
			$("#add_result").html(html);
			} 
			});
			
			});
			
			});
			</script>
			 <form class="form-horizontal">
			    <fieldset>
			      <div id="legend">
			        <legend class="">Add New TTC</legend>
			      </div>
			 
			      <!-- Name -->
			      <div class="control-group">
			        <label class="control-label"  for="Ttc_name">TTC Name</label>
			        <div class="controls">
			          <input type="text" id="ttc_name" placeholder="Write the TTC Name" class="input-xlarge">
			        </div>
			      </div>
			      
			       <!-- Province Name -->
			      <div class="control-group">
			        <label class="control-label" for="email">Select Province</label>
			        <div class="controls">
			          <select class="input-xlarge" id="ttc_province">
					  	<option value="">Please Select a Provice</option>
					  	<?php
					  	mysql_query ('SET NAMES utf8');
					  	mysql_query('SET CHARACTER_SET utf8'); 
					  	$q_t=mysql_query("SELECT * FROM province order by PROV_NAME");
					  	while($row=mysql_fetch_array($q_t)){
						  	echo "<option value='$row[PROV_ID]'>" . $row['PROV_NAME'] . "</option>";
						  	
						  	}
					  	
					  	?>
					  </select>
			        </div>
			      </div>
			      
			      
			      <!-- Card Number -->
			      <div class="control-group">
			        <label class="control-label" for="email">TTC TYPE</label>
			        <div class="controls">
			          <select class="input-xlarge" id="ttc_type">
					  	<option value="">Please Select TTC Type</option>
					  	<option value="اساسی">اساسی</option>
					  	<option value="الحاقیه">الحاقیه</option>
					  	<option value="مرکزحمایوی">مرکزحمایوی</option>
					  </select>
			        </div>
			      </div>
			 
			      <!-- Expiry-->
			      <div class="control-group">
			        <label class="control-label" for="status">Status</label>
			        <div class="controls">
			          <select class="input-xlarge" id="ttc_status">
			          <option value="">Select TTC Type</option>
			          <option value="فعال">فعال</option>
			          <option value="غیرفعال">غیرفعال</option>
			          </select>
			      
			        </div>
			      </div>
			 
			      <!-- CVV -->
			      <div class="control-group">
			        <label class="control-label"  for="location">Location</label>
			        <div class="controls">
			          <input type="text" id="ttc_location" placeholder="TTC Location" class="input-xlarge">
			        </div>
			      </div>
			 
			    
			 
			      <!-- Submit -->
			      <div class="control-group">
			        <div class="controls">
			          <button class="btn btn-success" id="sub_btn" onclick="javascript:void">Add TTC</button>
			        </div>
			      </div>
			 
			    </fieldset>
			  </form> 
			  
		  </div>
		  
		</div>


	<!--/Content-->
	
    </div>
	
	
	<div class="span3 well">
      <ul class="nav nav-list"> 
		  <li class="nav-header">Login Details</li>        
		  <li class="disabled"><a href="javascript:void"><i class="icon-signin"></i> Last Login:<?php echo date("F j, Y, g:i a");?></a></li>
          <li class="disabled"><a href="javascript:void"><i class="icon-user"></i> Your are logged in as:<?php echo "Data Entry";?></a></li>
		  <li class="divider"></li>
		   <li class="nav-header">User Panel</li> 
          
		  <li><a href="settings.php"><i class="icon-cog"></i> Settings</a></li>
		  <li><a href="controller/logout.php"><i class="icon-off"></i> Logout</a></li>
		</ul>
    </div>
  </div>
  <hr/>
  <footer class="footer">
  &copy;2013 TMIS, TED, MoE
  </footer>
</div>

</body>

</html>